package com.lyx.userserver.user.controller;

import com.lyx.common.utils.JwtUtils;
import com.lyx.common.vo.R;
import com.lyx.userserver.user.service.UserService;
import com.lyx.userserver.user.vo.UserVO;
import io.jsonwebtoken.Claims;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * --- Be Humble and Hungry ---
 *
 * @author McMeloxD
 * @date 2024/8/19
 * @desc
 */
@RestController
@RequestMapping("/app/user")
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("/my")
    public R<UserVO> my(HttpServletRequest request) {
        String jwt = request.getHeader("Token");
        Claims clamims = JwtUtils.parseJWT(jwt);
        Object uid = clamims.get("uid");
        UserVO my = userService.my(Integer.parseInt(uid.toString()));
        return R.ok(my);
    }
}
